{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Examine & consume web services in Python with azureml-model-management-sdk"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "                               ***Applies to: Machine Learning Server 9.2***"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Prerequisite\n",
    "\n",
    "In this example, we assume you have already completed [the Publish Quickstart](https://docs.microsoft.com/machine-learning-server/operationalize/python/quickstart-deploy-python-web-service) and there is a web service called 'TxService v1.0' hosted in your instance of Machine Learning Server. \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. Authenticate and initiate the  `DeployClient`\n",
    "\n",
    "There are several ways to authentication against Machine Learning Server. Choose the authentication method configured by your administrator. Contact your administrator for authentication credentials.\n",
    "\n",
    "For simplicity, this example uses the local 'admin' account for authentication.  \n",
    "\n",
    "1. Import the DeployClient and MLServer classes from the [azureml-model-management-sdk package](https://docs.microsoft.com/en-us/r-server/python-reference/azureml-model-management-sdk/azureml-model-management-sdk) to connect to Machine Learning Server (`use=MLServer`).\n",
    "\n",
    "1. Provide **the connection details for your host and context** into the corresponding fields. Learn more in the article [Connecting to Machine Learning Server in Python](https://docs.microsoft.com/en-us/r-server/operationalize/python/how-to-authenticate-in-python)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# -- Import the DeployClient and MLServer classes from the azureml-model-management-sdk package.\n",
    "from azureml.deploy import DeployClient\n",
    "from azureml.deploy.server import MLServer\n",
    "\n",
    "# -- Define the location of Machine Learning Server --\n",
    "# -- for local onebox: http://localhost:12800\n",
    "HOST = 'http://localhost:12800'\n",
    "context = ('admin', 'YOUR_ADMIN_PASSWORD')\n",
    "client = DeployClient(HOST, use=MLServer, auth=context)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You are now authenticated. \n",
    "\n",
    "The **DeployClient** can interact with the web service management APIs to deploy, list, consume and so on. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. Get the service you want to explore and consume\n",
    "\n",
    "In a production environment, the data scientist who deployed the service would likely inform you that the new service is ready for testing or production. They should provide you with its name and version."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.a.    Get a list of services\n",
    "\n",
    "You can get a list of the services available on Machine Learning Server using the `list_services` function on the `DeployClient` object we initiated at the beginning of the notebook. [Learn more about list_services.](https://docs.microsoft.com/machine-learning-server/operationalize/python/how-to-consume-web-services#list_services)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'code': \"def manualTransmission(hp, wt):\\n    import pandas as pd\\n    from revoscalepy import rx_predict\\n    from matplotlib import pyplot as plt\\n    \\n    # -- make the prediction use model `cars_model` and input data --\\n    newData = pd.DataFrame({'hp':[hp], 'wt':[wt]})\\n    answer = rx_predict(cars_model, newData, type='response')\\n    \\n    # -- save some files to demonstrate the ability to return file artifacts --\\n    answer.to_csv('answer.csv')\\n    # return prediction\\n    return answer\\n\\nanswer = manualTransmission(hp, wt)\",\n",
       "  'creationTime': '2017-09-20T19:35:18.0561232',\n",
       "  'description': 'My first python model',\n",
       "  'initCode': 'def init():\\n    import pandas as pd\\n    from revoscalepy import rx_predict\\n    from matplotlib import pyplot as plt\\n\\ninit()',\n",
       "  'inputParameterDefinitions': [{'name': 'hp', 'type': 'numeric'},\n",
       "   {'name': 'wt', 'type': 'numeric'}],\n",
       "  'myPermissionOnService': 'read/write',\n",
       "  'name': 'TxService',\n",
       "  'operationId': 'manualTransmission',\n",
       "  'outputFileNames': ['answer.csv', 'image.png'],\n",
       "  'outputParameterDefinitions': [{'name': 'answer', 'type': 'data.frame'}],\n",
       "  'runtimeType': 'Python',\n",
       "  'snapshotId': '8896f726-5c18-49c9-b427-95422d40bcb9',\n",
       "  'version': '1.0',\n",
       "  'versionPublishedBy': 'admin'}]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# -- List all services by this name --\n",
    "client.list_services('TxService')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can now see all versions of TxService. There may be one or more. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.b.  Get the service object for TxService 1.0\n",
    "\n",
    "You can retrieve the web service object for consumption by calling `get_service` on the `DeployClient` object. This object contains the client stub used to consume that service."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<TxserviceService> \n",
      "{   '_api': '/api/TxService/1.0',\n",
      "    '_http_client': <azureml.common.http_client.HttpClient object at 0x000000C74FE40EF0>,\n",
      "    '_service': {   '_fn': {   'args': 'self,hp,wt',\n",
      "                               'name': 'manualTransmission'},\n",
      "                    'code': 'def '\n",
      "                            'manualTransmission(hp, '\n",
      "                            'wt):\\n'\n",
      "                            '    '\n",
      "                            'import '\n",
      "                            'pandas '\n",
      "                            'as '\n",
      "                            'pd\\n'\n",
      "                            '    '\n",
      "                            'from '\n",
      "                            'revoscalepy '\n",
      "                            'import '\n",
      "                            'rx_predict\\n'\n",
      "                            '    '\n",
      "                            'from '\n",
      "                            'matplotlib '\n",
      "                            'import '\n",
      "                            'pyplot '\n",
      "                            'as '\n",
      "                            'plt\\n'\n",
      "                            '    \\n'\n",
      "                            '    '\n",
      "                            '# '\n",
      "                            '-- '\n",
      "                            'make '\n",
      "                            'the '\n",
      "                            'prediction '\n",
      "                            'use '\n",
      "                            'model '\n",
      "                            '`cars_model` '\n",
      "                            'and '\n",
      "                            'input '\n",
      "                            'data '\n",
      "                            '--\\n'\n",
      "                            '    '\n",
      "                            'newData '\n",
      "                            '= '\n",
      "                            \"pd.DataFrame({'hp':[hp], \"\n",
      "                            \"'wt':[wt]})\\n\"\n",
      "                            '    '\n",
      "                            'answer '\n",
      "                            '= '\n",
      "                            'rx_predict(cars_model, '\n",
      "                            'newData, '\n",
      "                            \"type='response')\\n\"\n",
      "                            '    \\n'\n",
      "                            '    '\n",
      "                            '# '\n",
      "                            '-- '\n",
      "                            'save '\n",
      "                            'some '\n",
      "                            'files '\n",
      "                            'to '\n",
      "                            'demonstrate '\n",
      "                            'the '\n",
      "                            'ability '\n",
      "                            'to '\n",
      "                            'return '\n",
      "                            'file '\n",
      "                            'artifacts '\n",
      "                            '--\\n'\n",
      "                            '    '\n",
      "                            \"answer.to_csv('answer.csv')\\n\"\n",
      "                            '    '\n",
      "                            '# '\n",
      "                            'return '\n",
      "                            'prediction\\n'\n",
      "                            '    '\n",
      "                            'return '\n",
      "                            'answer\\n'\n",
      "                            '\\n'\n",
      "                            'answer '\n",
      "                            '= '\n",
      "                            'manualTransmission(hp, '\n",
      "                            'wt)',\n",
      "                    'creationTime': '2017-09-20T19:35:18.0561232',\n",
      "                    'description': 'My '\n",
      "                                   'first '\n",
      "                                   'python '\n",
      "                                   'model',\n",
      "                    'initCode': 'def '\n",
      "                                'init():\\n'\n",
      "                                '    '\n",
      "                                'import '\n",
      "                                'pandas '\n",
      "                                'as '\n",
      "                                'pd\\n'\n",
      "                                '    '\n",
      "                                'from '\n",
      "                                'revoscalepy '\n",
      "                                'import '\n",
      "                                'rx_predict\\n'\n",
      "                                '    '\n",
      "                                'from '\n",
      "                                'matplotlib '\n",
      "                                'import '\n",
      "                                'pyplot '\n",
      "                                'as '\n",
      "                                'plt\\n'\n",
      "                                '\\n'\n",
      "                                'init()',\n",
      "                    'inputParameterDefinitions': [   {   'name': 'hp',\n",
      "                                                         'type': 'numeric'},\n",
      "                                                     {   'name': 'wt',\n",
      "                                                         'type': 'numeric'}],\n",
      "                    'myPermissionOnService': 'read/write',\n",
      "                    'name': 'TxService',\n",
      "                    'operationId': 'manualTransmission',\n",
      "                    'outputFileNames': [   'answer.csv',\n",
      "                                           'image.png'],\n",
      "                    'outputParameterDefinitions': [   {   'name': 'answer',\n",
      "                                                          'type': 'data.frame'}],\n",
      "                    'runtimeType': 'Python',\n",
      "                    'snapshotId': '8896f726-5c18-49c9-b427-95422d40bcb9',\n",
      "                    'version': '1.0',\n",
      "                    'versionPublishedBy': 'admin'}}\n"
     ]
    }
   ],
   "source": [
    "# -- Return the web service object for TxService 1.0 and assign to svc.\n",
    "svc = client.get_service('TxService', version='1.0')\n",
    "print(svc)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3. Explore the published web service\n",
    "\n",
    "Now let's:\n",
    "+ Use the `help` function to explore the published service. You can get help on any `azureml-model-management-sdk` functions, even those we dynamically generated ones to learn more about them.\n",
    "\n",
    "+ Print the capabilities that define the service holdings to see what the service can do and how it should be consumed. [Learn more about capabilities...](https://docs.microsoft.com/machine-learning-server/python-reference/azureml-model-management-sdk/service#capabilities)\n",
    "\n",
    "**Note:** Since you deployed the model as a web service, you can the code stored within a web service. However, unless you published the web service or are assigned to the \"Owner\" role, you won't be able to see the code contained in a service."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on TxserviceService in module azureml.deploy.server.service object:\n",
      "\n",
      "class TxserviceService(Service)\n",
      " |  Service object from metadata.\n",
      " |  \n",
      " |  Method resolution order:\n",
      " |      TxserviceService\n",
      " |      Service\n",
      " |      builtins.object\n",
      " |  \n",
      " |  Methods defined here:\n",
      " |  \n",
      " |  __init__(self, service, http_client)\n",
      " |      Constructor\n",
      " |      \n",
      " |      :param service:\n",
      " |      :param http_client:\n",
      " |  \n",
      " |  __str__(self)\n",
      " |      Return str(self).\n",
      " |  \n",
      " |  batch(self, records, parallel_count=10)\n",
      " |      Register a set of input records for batch execution on this service.\n",
      " |      \n",
      " |      :param records: The `data.frame` or `list` of\n",
      " |             input records to execute.\n",
      " |      :param parallel_count: Number of threads used to process entries in\n",
      " |             the batch. Default value is 10. Please make sure not to use too\n",
      " |             high of a number because it might negatively impact performance.\n",
      " |      :return: The `Batch` object to control service batching\n",
      " |              lifecycle.\n",
      " |  \n",
      " |  capabilities(self)\n",
      " |      Gets the service holding capabilities.\n",
      " |      \n",
      " |      :return: A dict of key/values describing the service.\n",
      " |  \n",
      " |  get_batch(self, execution_id)\n",
      " |      Retrieve the `Batch` based on an `execution id`\n",
      " |      \n",
      " |      :param execution_id: The id of the batch execution.\n",
      " |      :return: The `Batch`.\n",
      " |  \n",
      " |  list_batch_executions(self)\n",
      " |      Gets all batch executions currently queued for this service.\n",
      " |      \n",
      " |      :return: A list of `execution ids`.\n",
      " |  \n",
      " |  manualTransmission(self, hp, wt)\n",
      " |      Consume the TxService service.\n",
      " |      \n",
      " |      My first python model\n",
      " |      \n",
      " |      :param float hp: The required service input.\n",
      " |      :param float wt: The required service input.    \n",
      " |      :returns ServiceResponse: The `<ServiceResponse>` object contains the set of\n",
      " |          expected output values and artifacts. The possible outputs include:\n",
      " |                  \n",
      " |          Output: pandas.DataFrame answer        \n",
      " |      \n",
      " |      :Raises:\n",
      " |          HttpException: If server errors occur while executing the service.\n",
      " |          ValueError: If argument input types do not match the expected service\n",
      " |              input types.\n",
      " |  \n",
      " |  swagger(self)\n",
      " |      Retrieves the `swagger.json` for this service (see http://swagger.io/).\n",
      " |      :return: The swagger document for this service.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Static methods defined here:\n",
      " |  \n",
      " |  __new__(cls, *args, **kwargs)\n",
      " |      Create and return a new object.  See help(type) for accurate signature.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Data descriptors defined here:\n",
      " |  \n",
      " |  __dict__\n",
      " |      dictionary for instance variables (if defined)\n",
      " |  \n",
      " |  __weakref__\n",
      " |      list of weak references to the object (if defined)\n",
      "\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "# -- Learn more about the service.\n",
    "print(help(svc))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'api': '/api/TxService/1.0',\n",
       " 'artifacts': ['answer.csv', 'image.png'],\n",
       " 'creation_time': '2017-09-20T19:35:18.0561232',\n",
       " 'description': 'My first python model',\n",
       " 'inputs': [{'name': 'hp', 'type': 'numeric'},\n",
       "  {'name': 'wt', 'type': 'numeric'}],\n",
       " 'inputs_encoded': [{'name': 'hp', 'type': 'float'},\n",
       "  {'name': 'wt', 'type': 'float'}],\n",
       " 'name': 'TxService',\n",
       " 'operation_id': 'manualTransmission',\n",
       " 'outputs': [{'name': 'answer', 'type': 'data.frame'}],\n",
       " 'outputs_encoded': [{'name': 'answer', 'type': 'pandas.DataFrame'}],\n",
       " 'public-functions': {'batch': 'batch(records, parallel_count=10)',\n",
       "  'capabilities': 'capabilities()',\n",
       "  'get_batch': 'get_batch(execution_id)',\n",
       "  'list_batch_execution': 'list_batch_execution()',\n",
       "  'manualTransmission': 'manualTransmission(self,hp,wt)',\n",
       "  'swagger': 'swagger(json=True)'},\n",
       " 'published_by': 'admin',\n",
       " 'runtime': 'Python',\n",
       " 'snapshot_id': '8896f726-5c18-49c9-b427-95422d40bcb9',\n",
       " 'swagger': 'http://localhost:12800/api/TxService/1.0/swagger.json',\n",
       " 'version': '1.0'}"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# -- View the service object's capabilities/schema.\n",
    "svc.capabilities()\n",
    "# -- Notice the available public functions."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4. Consume the service and make a prediction\n",
    "\n",
    "Once the service is published, you can consume it using the _service api_ object returned from `get_service` to verify that the results are as expected. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Anyone can test and consume the service using its auto-generated Swagger-based JSON file. This Swagger-based JSON file is specific to a given version of a service. You can easily get this file during the same authenticated session in which you published the service or after the fact as will do here. It can be downloaded to the local file system.  **You can share the resulting file with application developers or others testing your service.**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<ServiceResponse> \n",
      "   api: /api/TxService/1.0 \n",
      "   error: \n",
      "   console_output: Rows Read: 1, Total Rows Processed: 1, Total Chunk Time: Less than .001 seconds \n",
      "\n",
      "   outputs: {'answer':     am_Pred\n",
      "0  0.533267}\n",
      "   raw_outputs: {'answer': {'am_Pred': [0.5332668559970368]}}\n",
      "   artifacts: {'image.png': None, 'answer.csv': 'LGFtX1ByZWQNCjAsMC41MzMyNjY4NTU5OTcwMzY4DQo='}\n",
      "    am_Pred\n",
      "0  0.533267\n"
     ]
    }
   ],
   "source": [
    "# Start interacting with the service. Let's call the function `manualTransmission`.\n",
    "res = svc.manualTransmission(120, 2.8)\n",
    "\n",
    "# -- Print Response object to inspect what was returned --\n",
    "print(res)\n",
    "\n",
    "# -- Pluck out the named output `answer` and print --\n",
    "print(res.output('answer'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "http://localhost:12800/api/TxService/1.0/swagger.json\n"
     ]
    }
   ],
   "source": [
    "# -- Retrieve the URL of the swagger file that defines this service.\n",
    "cap = svc.capabilities()\n",
    "swagger_URL = cap['swagger']\n",
    "print(swagger_URL)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\r\n",
      "  \"swagger\": \"2.0\",\r\n",
      "  \"info\": {\r\n",
      "    \"description\": \"My first python model\",\r\n",
      "    \"title\": \"TxService\",\r\n",
      "    \"version\": \"1.0\"\r\n",
      "  },\r\n",
      "  \"schemes\": [\r\n",
      "    \"http\",\r\n",
      "    \"https\"\r\n",
      "  ],\r\n",
      "  \"securityDefinitions\": {\r\n",
      "    \"Bearer\": {\r\n",
      "      \"type\": \"apiKey\",\r\n",
      "      \"name\": \"Authorization\",\r\n",
      "      \"in\": \"header\"\r\n",
      "    }\r\n",
      "  },\r\n",
      "  \"tags\": [\r\n",
      "    {\r\n",
      "      \"name\": \"TxService\",\r\n",
      "      \"description\": \"My first python model\"\r\n",
      "    }\r\n",
      "  ],\r\n",
      "  \"consumes\": [\r\n",
      "    \"application/json\"\r\n",
      "  ],\r\n",
      "  \"produces\": [\r\n",
      "    \"application/json\"\r\n",
      "  ],\r\n",
      "  \"paths\": {\r\n",
      "    \"/login\": {\r\n",
      "      \"post\": {\r\n",
      "        \"operationId\": \"login\",\r\n",
      "        \"summary\": \"Logs the user in\",\r\n",
      "        \"parameters\": [\r\n",
      "          {\r\n",
      "            \"name\": \"loginRequest\",\r\n",
      "            \"in\": \"body\",\r\n",
      "            \"required\": true,\r\n",
      "            \"schema\": {\r\n",
      "              \"$ref\": \"#/definitions/LoginRequest\"\r\n",
      "            }\r\n",
      "          }\r\n",
      "        ],\r\n",
      "        \"tags\": [\r\n",
      "          \"User\"\r\n",
      "        ],\r\n",
      "        \"responses\": {\r\n",
      "          \"200\": {\r\n",
      "            \"description\": \"Login successful\",\r\n",
      "            \"schema\": {\r\n",
      "              \"$ref\": \"#/definitions/AccessTokenResponse\"\r\n",
      "            }\r\n",
      "          },\r\n",
      "          \"default\": {\r\n",
      "            \"description\": \"Error \\n * 401 - Invalid Password\",\r\n",
      "            \"schema\": {\r\n",
      "              \"$ref\": \"#/definitions/Error\"\r\n",
      "            }\r\n",
      "          }\r\n",
      "        }\r\n",
      "      }\r\n",
      "    },\r\n",
      "    \"/login/refreshToken\": {\r\n",
      "      \"post\": {\r\n",
      "        \"operationId\": \"renewToken\",\r\n",
      "        \"summary\": \"The user renews access token and refresh token\",\r\n",
      "        \"parameters\": [\r\n",
      "          {\r\n",
      "            \"name\": \"renewTokenRequest\",\r\n",
      "            \"in\": \"body\",\r\n",
      "            \"required\": true,\r\n",
      "            \"schema\": {\r\n",
      "              \"$ref\": \"#/definitions/RenewTokenRequest\"\r\n",
      "            }\r\n",
      "          }\r\n",
      "        ],\r\n",
      "        \"tags\": [\r\n",
      "          \"User\"\r\n",
      "        ],\r\n",
      "        \"responses\": {\r\n",
      "          \"200\": {\r\n",
      "            \"description\": \"Access token and refresh token updated successfully\",\r\n",
      "            \"schema\": {\r\n",
      "              \"$ref\": \"#/definitions/AccessTokenResponse\"\r\n",
      "            }\r\n",
      "          },\r\n",
      "          \"default\": {\r\n",
      "            \"description\": \"Error \\n * 401 - Invalid or expired refresh token\",\r\n",
      "            \"schema\": {\r\n",
      "              \"$ref\": \"#/definitions/Error\"\r\n",
      "            }\r\n",
      "          }\r\n",
      "        }\r\n",
      "      },\r\n",
      "      \"delete\": {\r\n",
      "        \"operationId\": \"revokeRefreshToken\",\r\n",
      "        \"summary\": \"The user revokes a refresh token\",\r\n",
      "        \"parameters\": [\r\n",
      "          {\r\n",
      "            \"name\": \"refreshToken\",\r\n",
      "            \"in\": \"query\",\r\n",
      "            \"description\": \"The refresh token to be revoked\",\r\n",
      "            \"required\": true,\r\n",
      "            \"type\": \"string\"\r\n",
      "          }\r\n",
      "        ],\r\n",
      "        \"tags\": [\r\n",
      "          \"User\"\r\n",
      "        ],\r\n",
      "        \"responses\": {\r\n",
      "          \"200\": {\r\n",
      "            \"description\": \"Refresh token updated successfully\",\r\n",
      "            \"schema\": {\r\n",
      "              \"$ref\": \"#/definitions/AccessTokenResponse\"\r\n",
      "            }\r\n",
      "          },\r\n",
      "          \"default\": {\r\n",
      "            \"description\": \"Error \\n * 401 - Invalid or expired refresh token\",\r\n",
      "            \"schema\": {\r\n",
      "              \"$ref\": \"#/definitions/Error\"\r\n",
      "            }\r\n",
      "          }\r\n",
      "        }\r\n",
      "      }\r\n",
      "    },\r\n",
      "    \"/api/TxService/1.0\": {\r\n",
      "      \"post\": {\r\n",
      "        \"security\": [\r\n",
      "          {\r\n",
      "            \"Bearer\": []\r\n",
      "          }\r\n",
      "        ],\r\n",
      "        \"tags\": [\r\n",
      "          \"TxService\"\r\n",
      "        ],\r\n",
      "        \"description\": \"Consume the TxService web service.\",\r\n",
      "        \"operationId\": \"manualTransmission\",\r\n",
      "        \"parameters\": [\r\n",
      "          {\r\n",
      "            \"name\": \"WebServiceParameters\",\r\n",
      "            \"in\": \"body\",\r\n",
      "            \"required\": true,\r\n",
      "            \"description\": \"Input parameters to the web service.\",\r\n",
      "            \"schema\": {\r\n",
      "              \"$ref\": \"#/definitions/InputParameters\"\r\n",
      "            }\r\n",
      "          }\r\n",
      "        ],\r\n",
      "        \"responses\": {\r\n",
      "          \"200\": {\r\n",
      "            \"description\": \"OK\",\r\n",
      "            \"schema\": {\r\n",
      "              \"$ref\": \"#/definitions/WebServiceResult\"\r\n",
      "            }\r\n",
      "          },\r\n",
      "          \"400\": {\r\n",
      "            \"description\": \"Bad Request.\"\r\n",
      "          },\r\n",
      "          \"500\": {\r\n",
      "            \"description\": \"Internal Server Error.\"\r\n",
      "          },\r\n",
      "          \"default\": {\r\n",
      "            \"description\": \"Unexpected error.\",\r\n",
      "            \"schema\": {\r\n",
      "              \"$ref\": \"#/definitions/Error\"\r\n",
      "            }\r\n",
      "          }\r\n",
      "        }\r\n",
      "      }\r\n",
      "    },\r\n",
      "    \"/api/TxService/1.0/batch\": {\r\n",
      "      \"post\": {\r\n",
      "        \"security\": [\r\n",
      "          {\r\n",
      "            \"Bearer\": []\r\n",
      "          }\r\n",
      "        ],\r\n",
      "        \"tags\": [\r\n",
      "          \"TxService\"\r\n",
      "        ],\r\n",
      "        \"description\": \"Consume the TxService web service asynchronously.\",\r\n",
      "        \"operationId\": \"StartBatchExecution\",\r\n",
      "        \"parameters\": [\r\n",
      "          {\r\n",
      "            \"name\": \"BatchWebServiceParameters\",\r\n",
      "            \"in\": \"body\",\r\n",
      "            \"required\": true,\r\n",
      "            \"description\": \"Input parameters to the web service.\",\r\n",
      "            \"schema\": {\r\n",
      "              \"type\": \"array\",\r\n",
      "              \"items\": {\r\n",
      "                \"$ref\": \"#/definitions/InputParameters\"\r\n",
      "              }\r\n",
      "            }\r\n",
      "          },\r\n",
      "          {\r\n",
      "            \"name\": \"parallelCount\",\r\n",
      "            \"in\": \"query\",\r\n",
      "            \"description\": \"Number of threads used to process entries in the batch. Default value is 10. Please make sure not to use too high of a number because it might negatively impact performance.\",\r\n",
      "            \"required\": false,\r\n",
      "            \"type\": \"integer\",\r\n",
      "            \"format\": \"int32\"\r\n",
      "          }\r\n",
      "        ],\r\n",
      "        \"responses\": {\r\n",
      "          \"202\": {\r\n",
      "            \"description\": \"Accepted\",\r\n",
      "            \"schema\": {\r\n",
      "              \"$ref\": \"#/definitions/StartBatchExecutionResponse\"\r\n",
      "            }\r\n",
      "          },\r\n",
      "          \"400\": {\r\n",
      "            \"description\": \"Bad Request.\"\r\n",
      "          },\r\n",
      "          \"500\": {\r\n",
      "            \"description\": \"Internal Server Error.\"\r\n",
      "          },\r\n",
      "          \"default\": {\r\n",
      "            \"description\": \"Unexpected error.\",\r\n",
      "            \"schema\": {\r\n",
      "              \"$ref\": \"#/definitions/Error\"\r\n",
      "            }\r\n",
      "          }\r\n",
      "        }\r\n",
      "      },\r\n",
      "      \"get\": {\r\n",
      "        \"security\": [\r\n",
      "          {\r\n",
      "            \"Bearer\": []\r\n",
      "          }\r\n",
      "        ],\r\n",
      "        \"tags\": [\r\n",
      "          \"TxService\"\r\n",
      "        ],\r\n",
      "        \"summary\": \"Gets all batch executions for TxService.\",\r\n",
      "        \"operationId\": \"GetBatchExecutions\",\r\n",
      "        \"consumes\": [\r\n",
      "          \"application/json\"\r\n",
      "        ],\r\n",
      "        \"produces\": [\r\n",
      "          \"application/json\"\r\n",
      "        ],\r\n",
      "        \"responses\": {\r\n",
      "          \"200\": {\r\n",
      "            \"description\": \"OK\",\r\n",
      "            \"schema\": {\r\n",
      "              \"type\": \"array\",\r\n",
      "              \"items\": {\r\n",
      "                \"type\": \"string\"\r\n",
      "              }\r\n",
      "            }\r\n",
      "          },\r\n",
      "          \"default\": {\r\n",
      "            \"description\": \"Error \\n * 404 - Web service not found \\n * 400 - Bad request\",\r\n",
      "            \"schema\": {\r\n",
      "              \"$ref\": \"#/definitions/Error\"\r\n",
      "            }\r\n",
      "          }\r\n",
      "        }\r\n",
      "      }\r\n",
      "    },\r\n",
      "    \"/api/TxService/1.0/batch/{executionId}\": {\r\n",
      "      \"get\": {\r\n",
      "        \"security\": [\r\n",
      "          {\r\n",
      "            \"Bearer\": []\r\n",
      "          }\r\n",
      "        ],\r\n",
      "        \"tags\": [\r\n",
      "          \"TxService\"\r\n",
      "        ],\r\n",
      "        \"summary\": \"Gets all batch executions for TxService.\",\r\n",
      "        \"operationId\": \"GetBatchExecutionStatus\",\r\n",
      "        \"consumes\": [\r\n",
      "          \"application/json\"\r\n",
      "        ],\r\n",
      "        \"produces\": [\r\n",
      "          \"application/json\"\r\n",
      "        ],\r\n",
      "        \"parameters\": [\r\n",
      "          {\r\n",
      "            \"name\": \"executionId\",\r\n",
      "            \"in\": \"path\",\r\n",
      "            \"description\": \"Execution id of the execution\",\r\n",
      "            \"required\": true,\r\n",
      "            \"type\": \"string\"\r\n",
      "          },\r\n",
      "          {\r\n",
      "            \"name\": \"showPartialResults\",\r\n",
      "            \"in\": \"query\",\r\n",
      "            \"description\": \"Returns the already processed results of the batch execution even if it hasn't been fully completed.\",\r\n",
      "            \"required\": false,\r\n",
      "            \"type\": \"boolean\"\r\n",
      "          }\r\n",
      "        ],\r\n",
      "        \"responses\": {\r\n",
      "          \"200\": {\r\n",
      "            \"description\": \"OK\",\r\n",
      "            \"schema\": {\r\n",
      "              \"$ref\": \"#/definitions/BatchWebServiceResult\"\r\n",
      "            }\r\n",
      "          },\r\n",
      "          \"default\": {\r\n",
      "            \"description\": \"Error \\n * 404 - Web service not found \\n * 404 - Execution not found \\n * 400 - Bad request\",\r\n",
      "            \"schema\": {\r\n",
      "              \"$ref\": \"#/definitions/Error\"\r\n",
      "            }\r\n",
      "          }\r\n",
      "        }\r\n",
      "      },\r\n",
      "      \"delete\": {\r\n",
      "        \"security\": [\r\n",
      "          {\r\n",
      "            \"Bearer\": []\r\n",
      "          }\r\n",
      "        ],\r\n",
      "        \"tags\": [\r\n",
      "          \"TxService\"\r\n",
      "        ],\r\n",
      "        \"summary\": \"Cancels and deletes all batch executions for TxService.\",\r\n",
      "        \"operationId\": \"CancelAndDeleteBatchExecution\",\r\n",
      "        \"consumes\": [\r\n",
      "          \"application/json\"\r\n",
      "        ],\r\n",
      "        \"produces\": [\r\n",
      "          \"application/json\"\r\n",
      "        ],\r\n",
      "        \"parameters\": [\r\n",
      "          {\r\n",
      "            \"name\": \"executionId\",\r\n",
      "            \"in\": \"path\",\r\n",
      "            \"description\": \"Execution id of the execution.\",\r\n",
      "            \"required\": true,\r\n",
      "            \"type\": \"string\"\r\n",
      "          }\r\n",
      "        ],\r\n",
      "        \"responses\": {\r\n",
      "          \"200\": {\r\n",
      "            \"description\": \"OK\",\r\n",
      "            \"schema\": {\r\n",
      "              \"type\": \"array\",\r\n",
      "              \"items\": {\r\n",
      "                \"type\": \"string\"\r\n",
      "              }\r\n",
      "            }\r\n",
      "          },\r\n",
      "          \"default\": {\r\n",
      "            \"description\": \"Error \\n * 404 - Web service not found \\n * 404 - Execution not found \\n * 400 - Bad request\",\r\n",
      "            \"schema\": {\r\n",
      "              \"$ref\": \"#/definitions/Error\"\r\n",
      "            }\r\n",
      "          }\r\n",
      "        }\r\n",
      "      }\r\n",
      "    },\r\n",
      "    \"/api/TxService/1.0/batch/{executionId}/{index}/files\": {\r\n",
      "      \"get\": {\r\n",
      "        \"security\": [\r\n",
      "          {\r\n",
      "            \"Bearer\": []\r\n",
      "          }\r\n",
      "        ],\r\n",
      "        \"tags\": [\r\n",
      "          \"TxService\"\r\n",
      "        ],\r\n",
      "        \"summary\": \"Gets all files from an individual execution in TxService.\",\r\n",
      "        \"operationId\": \"GetBatchExecutionFiles\",\r\n",
      "        \"consumes\": [\r\n",
      "          \"application/json\"\r\n",
      "        ],\r\n",
      "        \"produces\": [\r\n",
      "          \"application/json\"\r\n",
      "        ],\r\n",
      "        \"parameters\": [\r\n",
      "          {\r\n",
      "            \"name\": \"executionId\",\r\n",
      "            \"in\": \"path\",\r\n",
      "            \"description\": \"Execution id of the execution\",\r\n",
      "            \"required\": true,\r\n",
      "            \"type\": \"string\"\r\n",
      "          },\r\n",
      "          {\r\n",
      "            \"name\": \"index\",\r\n",
      "            \"in\": \"path\",\r\n",
      "            \"description\": \"Index of the execution in the batch.\",\r\n",
      "            \"required\": true,\r\n",
      "            \"type\": \"integer\"\r\n",
      "          }\r\n",
      "        ],\r\n",
      "        \"responses\": {\r\n",
      "          \"200\": {\r\n",
      "            \"description\": \"OK\",\r\n",
      "            \"schema\": {\r\n",
      "              \"type\": \"array\",\r\n",
      "              \"items\": {\r\n",
      "                \"type\": \"string\"\r\n",
      "              }\r\n",
      "            }\r\n",
      "          },\r\n",
      "          \"default\": {\r\n",
      "            \"description\": \"Error \\n * 404 - Web service not found \\n * 404 - Execution not found \\n * 400 - Bad request\",\r\n",
      "            \"schema\": {\r\n",
      "              \"$ref\": \"#/definitions/Error\"\r\n",
      "            }\r\n",
      "          }\r\n",
      "        }\r\n",
      "      }\r\n",
      "    },\r\n",
      "    \"/api/TxService/1.0/batch/{executionId}/{index}/files/{fileName}\": {\r\n",
      "      \"get\": {\r\n",
      "        \"security\": [\r\n",
      "          {\r\n",
      "            \"Bearer\": []\r\n",
      "          }\r\n",
      "        ],\r\n",
      "        \"tags\": [\r\n",
      "          \"TxService\"\r\n",
      "        ],\r\n",
      "        \"summary\": \"Gets a specific file from an execution in TxService.\",\r\n",
      "        \"operationId\": \"GetBatchExecutionFile\",\r\n",
      "        \"consumes\": [\r\n",
      "          \"application/json\"\r\n",
      "        ],\r\n",
      "        \"produces\": [\r\n",
      "          \"application/json\"\r\n",
      "        ],\r\n",
      "        \"parameters\": [\r\n",
      "          {\r\n",
      "            \"name\": \"executionId\",\r\n",
      "            \"in\": \"path\",\r\n",
      "            \"description\": \"Execution id of the execution\",\r\n",
      "            \"required\": true,\r\n",
      "            \"type\": \"string\"\r\n",
      "          },\r\n",
      "          {\r\n",
      "            \"name\": \"index\",\r\n",
      "            \"in\": \"path\",\r\n",
      "            \"description\": \"Index of the execution in the batch.\",\r\n",
      "            \"required\": true,\r\n",
      "            \"type\": \"integer\"\r\n",
      "          },\r\n",
      "          {\r\n",
      "            \"name\": \"fileName\",\r\n",
      "            \"in\": \"path\",\r\n",
      "            \"description\": \"Name of the file to be returned.\",\r\n",
      "            \"required\": true,\r\n",
      "            \"type\": \"string\"\r\n",
      "          }\r\n",
      "        ],\r\n",
      "        \"responses\": {\r\n",
      "          \"200\": {\r\n",
      "            \"description\": \"OK\",\r\n",
      "            \"schema\": {\r\n",
      "              \"type\": \"file\"\r\n",
      "            }\r\n",
      "          },\r\n",
      "          \"default\": {\r\n",
      "            \"description\": \"Error \\n * 404 - Web service not found \\n * 404 - Execution not found \\n * 404 - File not found \\n * 400 - Bad request\",\r\n",
      "            \"schema\": {\r\n",
      "              \"$ref\": \"#/definitions/Error\"\r\n",
      "            }\r\n",
      "          }\r\n",
      "        }\r\n",
      "      }\r\n",
      "    }\r\n",
      "  },\r\n",
      "  \"definitions\": {\r\n",
      "    \"InputParameters\": {\r\n",
      "      \"type\": \"object\",\r\n",
      "      \"properties\": {\r\n",
      "        \"hp\": {\r\n",
      "          \"type\": \"number\",\r\n",
      "          \"description\": \"numeric\"\r\n",
      "        },\r\n",
      "        \"wt\": {\r\n",
      "          \"type\": \"number\",\r\n",
      "          \"description\": \"numeric\"\r\n",
      "        }\r\n",
      "      }\r\n",
      "    },\r\n",
      "    \"OutputParameters\": {\r\n",
      "      \"type\": \"object\",\r\n",
      "      \"properties\": {\r\n",
      "        \"answer\": {\r\n",
      "          \"type\": \"object\",\r\n",
      "          \"description\": \"data.frame\"\r\n",
      "        }\r\n",
      "      }\r\n",
      "    },\r\n",
      "    \"Error\": {\r\n",
      "      \"type\": \"object\",\r\n",
      "      \"properties\": {\r\n",
      "        \"code\": {\r\n",
      "          \"type\": \"integer\",\r\n",
      "          \"format\": \"int32\"\r\n",
      "        },\r\n",
      "        \"message\": {\r\n",
      "          \"type\": \"string\"\r\n",
      "        },\r\n",
      "        \"fields\": {\r\n",
      "          \"type\": \"string\"\r\n",
      "        }\r\n",
      "      }\r\n",
      "    },\r\n",
      "    \"WebServiceResult\": {\r\n",
      "      \"type\": \"object\",\r\n",
      "      \"properties\": {\r\n",
      "        \"success\": {\r\n",
      "          \"type\": \"boolean\",\r\n",
      "          \"description\": \"Boolean flag indicating the success status of web service execution.\"\r\n",
      "        },\r\n",
      "        \"errorMessage\": {\r\n",
      "          \"type\": \"string\",\r\n",
      "          \"description\": \"Error messages if any occurred during the web service execution.\"\r\n",
      "        },\r\n",
      "        \"consoleOutput\": {\r\n",
      "          \"type\": \"string\",\r\n",
      "          \"description\": \"Console output from the web service execution.\"\r\n",
      "        },\r\n",
      "        \"changedFiles\": {\r\n",
      "          \"type\": \"array\",\r\n",
      "          \"items\": {\r\n",
      "            \"type\": \"string\",\r\n",
      "            \"description\": \"The filename of a modified file during the web service execution.\"\r\n",
      "          },\r\n",
      "          \"description\": \"The filenames of the files modified during the web service execution.\"\r\n",
      "        },\r\n",
      "        \"outputFiles\": {\r\n",
      "          \"type\": \"object\",\r\n",
      "          \"additionalProperties\": {\r\n",
      "            \"type\": \"string\",\r\n",
      "            \"format\": \"byte\"\r\n",
      "          }\r\n",
      "        },\r\n",
      "        \"outputParameters\": {\r\n",
      "          \"$ref\": \"#/definitions/OutputParameters\"\r\n",
      "        }\r\n",
      "      }\r\n",
      "    },\r\n",
      "    \"StartBatchExecutionResponse\": {\r\n",
      "      \"type\": \"object\",\r\n",
      "      \"properties\": {\r\n",
      "        \"batchExecutionId\": {\r\n",
      "          \"type\": \"string\",\r\n",
      "          \"description\": \"Id of the asynchronous execution.\"\r\n",
      "        }\r\n",
      "      }\r\n",
      "    },\r\n",
      "    \"BatchWebServiceResult\": {\r\n",
      "      \"type\": \"object\",\r\n",
      "      \"properties\": {\r\n",
      "        \"state\": {\r\n",
      "          \"type\": \"string\",\r\n",
      "          \"enum\": [\r\n",
      "            \"pending\",\r\n",
      "            \"inProgress\",\r\n",
      "            \"ready\",\r\n",
      "            \"complete\"\r\n",
      "          ],\r\n",
      "          \"description\": \"State of the execution. Can be of the following values:\\n - Pending: The batch execution was submitted but is not yet scheduled.\\nReady: The batch execution was submitted and can be executed.\\nInProgress: The batch execution is currently being processed.\\nComplete: The batch execution has been completed.\"\r\n",
      "        },\r\n",
      "        \"completedItemCount\": {\r\n",
      "          \"type\": \"integer\",\r\n",
      "          \"format\": \"int32\",\r\n",
      "          \"description\": \"Number of completed items in this batch operation.\"\r\n",
      "        },\r\n",
      "        \"totalItemCount\": {\r\n",
      "          \"type\": \"integer\",\r\n",
      "          \"format\": \"int32\",\r\n",
      "          \"description\": \"Number of total items in this batch operation.\"\r\n",
      "        },\r\n",
      "        \"batchExecutionResults\": {\r\n",
      "          \"type\": \"array\",\r\n",
      "          \"items\": {\r\n",
      "            \"$ref\": \"#/definitions/WebServiceResult\"\r\n",
      "          },\r\n",
      "          \"description\": \"The responses of the individual executions.\"\r\n",
      "        }\r\n",
      "      }\r\n",
      "    },\r\n",
      "    \"LoginRequest\": {\r\n",
      "      \"type\": \"object\",\r\n",
      "      \"properties\": {\r\n",
      "        \"username\": {\r\n",
      "          \"type\": \"string\",\r\n",
      "          \"description\": \"The name of the user.\"\r\n",
      "        },\r\n",
      "        \"password\": {\r\n",
      "          \"type\": \"string\",\r\n",
      "          \"description\": \"The password of the user.\"\r\n",
      "        }\r\n",
      "      }\r\n",
      "    },\r\n",
      "    \"RenewTokenRequest\": {\r\n",
      "      \"type\": \"object\",\r\n",
      "      \"properties\": {\r\n",
      "        \"refreshToken\": {\r\n",
      "          \"type\": \"string\",\r\n",
      "          \"description\": \"A currently valid refresh token.\"\r\n",
      "        }\r\n",
      "      }\r\n",
      "    },\r\n",
      "    \"AccessTokenResponse\": {\r\n",
      "      \"type\": \"object\",\r\n",
      "      \"properties\": {\r\n",
      "        \"token_type\": {\r\n",
      "          \"type\": \"string\"\r\n",
      "        },\r\n",
      "        \"access_token\": {\r\n",
      "          \"type\": \"string\"\r\n",
      "        },\r\n",
      "        \"expires_on\": {\r\n",
      "          \"type\": \"string\"\r\n",
      "        },\r\n",
      "        \"refresh_token\": {\r\n",
      "          \"type\": \"string\"\r\n",
      "        }\r\n",
      "      }\r\n",
      "    }\r\n",
      "  }\r\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "# -- Print the contents of the swagger doc\n",
    "print(svc.swagger())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
